package com.xbongbong.saas.script.tempenum;

import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.pro.enums.CommunicatePlanNotifyTypeEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.business.PushNotifyEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 跟进提醒刷脚本枚举
 *
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/15 15:42
 * @since v1.0
 */
@Getter
public enum TempPushNotifyEnum {
    //刷脚本专用枚举
    TITLE(PushNotifyEnum.TITLE),
    NOTIFY_NAME(PushNotifyEnum.NOTIFY_NAME),
    EXECUTOR(PushNotifyEnum.EXECUTOR),
    EXECUTOR_LINKED_TEXT(PushNotifyEnum.EXECUTOR_LINKED_TEXT),
    COMMUNICATE_TIME(PushNotifyEnum.COMMUNICATE_TIME),
    NOTIFY_TYPE(PushNotifyEnum.NOTIFY_TYPE),
    NOTIFY_TIME(PushNotifyEnum.NOTIFY_TIME),
    REPEAT_NOTIFY(PushNotifyEnum.REPEAT_NOTIFY),
    LOOP_NUM(PushNotifyEnum.LOOP_NUM),
    MEMO(PushNotifyEnum.MEMO),
    ENTER_COMMUNICATE_PLAN(PushNotifyEnum.ENTER_COMMUNICATE_PLAN),
    NOTIFY_NAME_LINKED_TEXT(PushNotifyEnum.NOTIFY_NAME_LINKED_TEXT),
    ;
    /**
     * 枚举
     */
    private PushNotifyEnum anEnum;

    TempPushNotifyEnum(PushNotifyEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempPushNotifyEnum> getAllEnum() {
        List<TempPushNotifyEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initNotifyName(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(BasicConstant.ZERO);
        fieldAttrEntity.setLinkedText(NOTIFY_NAME_LINKED_TEXT.anEnum.getAttr());
    }
    /**
     * 初始化提醒
     *
     * @param fieldAttrEntity 实体
     */
    public static void initNotifyType(FieldAttrEntity fieldAttrEntity) {
        String str = CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_QUARTER_HOUR.getAlias() + StringConstant.COMMA +
                CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_HOUR.getAlias() + StringConstant.COMMA +
                CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_DAY.getAlias() + StringConstant.COMMA +
                CommunicatePlanNotifyTypeEnum.ADVANCE_THREE_DAY.getAlias() + StringConstant.COMMA +
                CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_WEEK.getAlias() + StringConstant.COMMA ;
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItem(str));
        List<ItemPoJo> items = fieldAttrEntity.getItems();
        ItemPoJo itemPoJo = new ItemPoJo();
        itemPoJo.setText(CommunicatePlanNotifyTypeEnum.CUSTOM_TIME.getAlias());
        itemPoJo.setValue(CommunicatePlanNotifyTypeEnum.CUSTOM_TIME.getCode().toString());
        itemPoJo.setChecked(false);
        List<String> fieldMap = new ArrayList<>();
        fieldMap.add(NOTIFY_TIME.anEnum.getAttr());
        itemPoJo.setFieldMap(fieldMap);
        items.add(itemPoJo);
    }

    /**
     * 初始化跟进时间
     *
     * @param fieldAttrEntity 实体
     */
    public static void initCommunicateTime(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setDateLimit(DateTimeUtil.getTodayInt(DateTimeUtil.getInt()) - BasicConstant.ONE);
        saasParticularAttributePoJo.setLimitType(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 初始化重复提醒
     *
     * @param fieldAttrEntity 实体
     */
    public static void initRepeatNotify(FieldAttrEntity fieldAttrEntity) {
        String str = "不重复提醒,每天提醒,每周提醒,每月提醒,每年提醒";
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItem(str));
        List<ItemPoJo> items = fieldAttrEntity.getItems();
        for (ItemPoJo itemPoJo : items) {
            List<String> fieldMap = new ArrayList<>();
            fieldMap.add(LOOP_NUM.anEnum.getAttr());
            if (!Objects.equals(itemPoJo.getValue(), "1")){
                itemPoJo.setFieldMap(fieldMap);
            }
        }
    }

    /**
     * 初始化执行人
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initExecutor(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo1 = new ItemPoJo();
        itemPoJo1.setText("负责人");
        itemPoJo1.setValue("0");
        itemPoJo1.setChecked(true);
        itemPoJos.add(itemPoJo1);
        ItemPoJo itemPoJo2 = new ItemPoJo();
        itemPoJo2.setText("协同人");
        itemPoJo2.setValue("1");
        itemPoJo2.setChecked(false);
        itemPoJos.add(itemPoJo2);
        ItemPoJo itemPoJo3 = new ItemPoJo();
        itemPoJo3.setText("自定义");
        itemPoJo3.setValue("2");
        itemPoJo3.setChecked(false);
        List<String> fieldMap = new ArrayList<>();
        fieldMap.add(EXECUTOR_LINKED_TEXT.anEnum.getAttr());
        itemPoJo3.setFieldMap(fieldMap);
        itemPoJos.add(itemPoJo3);
        fieldAttrEntity.setItems(itemPoJos);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("custom");
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }
}
